package de.jmda.fx.node;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

import org.junit.Before;
import org.junit.Test;

public class JUT_Util
{
	private Group root;

	private VBox child_1;
	private HBox child_2;

	private VBox child_1_1;
	private VBox child_1_2;

	private HBox child_2_1;
	private HBox child_2_2;

	@Before
	public void beforeTest()
	{
		root = new Group();

		child_1 = new VBox();
		child_2 = new HBox();

		child_1_1 = new VBox();
		child_1_2 = new VBox();

		child_2_1 = new HBox();
		child_2_2 = new HBox();

		root.getChildren().add(child_1);
		root.getChildren().add(child_2);

		child_1.getChildren().add(child_1_1);
		child_1.getChildren().add(child_1_2);

		child_2.getChildren().add(child_2_1);
		child_2.getChildren().add(child_2_2);
	}

	@Test
	public void testFindMatch()
	{
		Node findNextParent = Util.findNextParentWithType(child_2_2, root.getClass());
		
		assertEquals(root, findNextParent);
	}

	@Test
	public void testFindNoMatch()
	{
		Node findNextParent = Util.findNextParentWithType(root, child_2_2.getClass());
		
		assertNull(findNextParent);
	}
}